﻿@model ProductReviewsModel
@using Nop.Web.Models.Catalog;
@{
    Layout = "~/Views/Shared/_Root.cshtml";

    //title
    Html.AddTitleParts(Model.ProductName);
    Html.AddTitleParts(T("PageTitle.ProductReviews").Text);
}
<div class="page product-reviews-page">
    <div class="page-title">
        <a href="@Url.RouteUrl("Product", new { SeName = Model.ProductSeName })">@Model.ProductName</a>
    </div>
    <div class="page-body">
        @Html.Widget("mobile_productreviews_page_top")
        @if (Model.AddProductReview.SuccessfullyAdded)
        {
            <div class="result">
                @Model.AddProductReview.Result
            </div>
        }
        else
        {
            <div class="write-review" id="review-form">
                @using (Html.BeginForm())
                {
                    <div class="title">
                        <strong>@T("Reviews.Write")</strong>
                    </div>
                    <div>
                        @Html.LabelFor(model => model.AddProductReview.Title)
                        @Html.TextBoxFor(model => model.AddProductReview.Title, new { @class = "review-title" })
                        @Html.ValidationMessageFor(model => model.AddProductReview.Title)
                    </div>
                    <div>
                        @Html.LabelFor(model => model.AddProductReview.ReviewText)
                        @Html.TextAreaFor(model => model.AddProductReview.ReviewText, new { @class = "review-text" })
                        @Html.ValidationMessageFor(model => model.AddProductReview.ReviewText)
                    </div>
                    <div data-role="fieldcontain">
                        <fieldset data-role="controlgroup" data-type="horizontal">
                            <legend>@Html.LabelFor(model => model.AddProductReview.Rating)</legend>
                            @for (int i = 1; i <= 5; i++)
                            {
                                string ratingControlId = "addproductrating" + i.ToString();
            
                                <input type="radio" name="@Html.FieldNameFor(model => model.AddProductReview.Rating)" id="@(ratingControlId)" value="@(i.ToString())" checked="@(i == Model.AddProductReview.Rating)" />
                                <label for="@(ratingControlId)">@(i.ToString())</label>
                            }
                        </fieldset>
                    </div>
                    <div class="message-error">
                        @Html.ValidationSummary(true)
                    </div>
                            if (Model.AddProductReview.DisplayCaptcha)
                            {
                    <div class="captcha-box">
                        @Html.Raw(Html.GenerateCaptcha())
                    </div>
                            }
                    <div class="buttons">             
                        <input type="submit" name="add-review" value="@T("Reviews.SubmitButton")" />   
                    </div>                 
                }
            </div>
        }
        @if (Model.Items.Count > 0)
        {
            <div class="product-review-list">
                <div class="title">
                    <strong>
                        @T("Reviews.ExistingReviews")
                    </strong>
                </div>
                <ul data-role="listview" data-inset="true" data-filter="false" data-theme="c">
                    @foreach (var review in Model.Items)
                    {
                        int ratingPercent = review.Rating * 20;                
                        <li>
                            <div class="product-review-item">
                                <div class="review-title">
                                    @review.Title
                                </div>
                                <div class="product-review-box">
                                    <div class="rating">
                                        <div style="width: @(ratingPercent)%">
                                        </div>
                                    </div>
                                </div>
                                <div class="review-text">
                                    @Html.Raw(Nop.Core.Html.HtmlHelper.FormatText(review.ReviewText, false, true, false, false, false, false))
                                </div>
                                <div class="review-info">
                                    <div>
                                        @T("Reviews.From"):
                                        @if (review.AllowViewingProfiles)
                                        {
                                            <a href="@Url.RouteUrl("CustomerProfile", new { id = review.CustomerId })">@(review.CustomerName)</a>
                                        }
                                        else
                                        {
                                            @review.CustomerName
                                        }
                                    </div>
                                    <div>
                                        @T("Reviews.Date"):
                                        @review.WrittenOnStr
                                    </div>
                                </div>
                                @Html.Partial("_ProductReviewHelpfulness", review.Helpfulness, new ViewDataDictionary())
                                @Html.Widget("mobile_productreviews_page_inside_review")
                            </div>
                        </li>
                    }
                </ul>
            </div>
        }
        @Html.Widget("mobile_productreviews_page_bottom")
    </div>
</div>